<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true" isELIgnored="false"%>
<%String ctx = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();session.setAttribute("ctx",ctx);%>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
    <link rel="stylesheet" type="text/css" href="${ctx}/resources/common/layui/css/layui.css" media="all">

    <script type="text/javascript" src="${ctx}/resources/common/layui/lay/dest/layui.all.js"></script>
    <script type="text/javascript" src="${ctx}/resources/common/js/jquery-1.12.4.min.js"></script>
    <script src="${ctx}/resources/common/layui/layer-v3.0.3/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="<%=ctx%>/resources/common/js/jQueryMD5.js"></script>
</head>

<body>
<form action="/user/test/index" method="post">
    <input type="text" name="username" id="username" value="test" />
    <input type="text" name="password" id="password" value="123" />
    <input type="button" id="login" value="提交" />
</form>
<script>
    $("#login").click(function(){
        $.ajax({
            url: "/admin/userLogin",
            dataType: "json",
            data: {username:$("#username").val(),password:$.md5($("#password").val())},
            type: "post",   //请求方式
            success: function(req) {
                console.log(req);
                console.log(JSON.stringify(req));
                if( req.status == 2 ){
                    location.href = "/admin/main";
                }else if( req.status == -1 ){
                    layer.msg('账号不存在', {
                        icon: 2,
                        time: 2000
                    });
                }else if( req.status == 0 ){
                    layer.msg('密码错误', {
                        icon: 2,
                        time: 2000
                    });
                }else if( req.status == 1 ){
                    layer.msg('账号已被锁定12小时', {
                        icon: 4,
                        time: 2000
                    });
                }
            },
            error: function(req) {
                console.log(JSON.stringify(req));
            }
        });
    });

</script>
</body>
</html>
